#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+7;
int a[N][2];
#define end '\n'
int main()
{
	int n,m;
	cin>>n>>m;
	int c=0;
	a[0][0]=1;
	while(m--)
	{
		int x;
		cin>>x;
		if(x==1)
		{
			c++;
			a[c][0]=a[c-1][0];
			a[c][1]=a[c-1][1];
			char y;
			cin>>y;
			if(y=='U')a[c][1]++;
			else if(y=='D')a[c][1]--;
			else if(y=='L')a[c][0]--;
			else a[c][0]++;
		}
		else
		{
			int y;
			cin>>y;
			if(c-y+1>=0)cout<<a[c-y+1][0]<<" "<<a[c-y+1][1]<<end;
			else cout<<y-c<<" "<<0<<end;
		}
	}
	return 0;
}
